<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>个人代办事项管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../../resources/styles/adminLTE/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet"
          href="../../resources/styles/adminLTE/bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../../resources/styles/adminLTE/bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../../resources/styles/adminLTE/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="../../resources/styles/adminLTE/dist/css/skins/_all-skins.min.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../../resources/styles/adminLTE/bower_components/morris.js/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../../resources/styles/adminLTE/bower_components/jvectormap/jquery-jvectormap.css">
    <!-- Date Picker -->
    <link rel="stylesheet"
          href="../../resources/styles/adminLTE/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet"
          href="../../resources/styles/adminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet"
          href="../../resources/styles/adminLTE/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--bootstrap-table 样式文件-->
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!--bootstrap-table 文件-->
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
    <!--bootstrap-table 文件-->
    <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    <link rel="stylesheet"
          href="../../resources/styles/css/main.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <header class="main-header">
        <!-- Logo -->
        <a href="index2.html" class="logo">
            <span class="logo-lg"><b>个人代办事项管理系统</b></span>
        </a>
        <nav class="navbar navbar-static-top">
            <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                <span class="sr-only">收起导航栏</span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <img src="../../resources/styles/adminLTE/dist/img/user2-160x160.jpg" class="user-image"
                                 alt="User Image">
                            欢迎您：<span id="hidden-xs"></span>
                        </a>

                    </li>

                </ul>
            </div>
        </nav>
    </header>

    <aside class="main-sidebar">

        <section class="sidebar">
            <ul class="sidebar-menu" data-widget="tree">
                <li class="header">导航栏</li>
                <li class="active treeview">
                    <a href="#">
                        <i class="fa fa-dashboard"></i> <span>系统管理</span>
                        <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
                    </a>
                    <ul class="treeview-menu">
                        <li class="active"><a href="/user/main"><i class="fa fa-circle-o"></i> 待办事项管理</a></li>
                        <li><a href="/user/infomation"><i class="fa fa-circle-o"></i> 个人信息维护</a></li>
                    </ul>
                </li>
            </ul>
        </section>

    </aside>


    <!--主面板开始-->
    <div class="content-wrapper">

        <section class="content-header">
            <h1>
                系统管理
                <small>待办事项管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">待办事项管理</li>
            </ol>
        </section>

        <div style="margin: 40px 20px 40px 20px">


            <table id="table"></table>

            <div id="toolbar" class="btn-group">
                <button id="btn_add" type="button" class="btn btn-default" onclick="showInsert()">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
                <button id="btn_edit" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
                </button>
                <button id="btn_delete" type="button" class="btn btn-default" onclick="deleteItems()">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                </button>
            </div>

        </div>

    </div>
    <!--主面板结束-->

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">查看待办事项</h4>
                </div>
                <div class="modal-body">

                    <div style="text-align: left">

                        <form>
                            <div class="form-group">
                                <label class="info_left">待办事项标题:</label>
                                <label class="info_right" id="search_todoItemTitle">—</label>
                            </div>
                            <div class="form-group">
                                <label class="info_left">待办事项内容:</label>
                                <br>
                                <label class="info_right" id="search_todoItemContent"
                                       style="height: 200px;padding-top: 20px">—</label>
                            </div>
                            <div class="form-group">
                                <label class="info_left">优先级:</label>
                                <label class="info_right" id="search_priority">—</label>
                            </div>
                            <div class="form-group">
                                <label class="info_left">创建时间:</label>
                                <label class="info_right" id="search_creationDate">—</label>
                            </div>
                            <div class="form-group">
                                <label class="info_left">更新时间:</label>
                                <label class="info_right" id="search_lastUpadateDate">—</label>
                            </div>
                            <div class="form-group">
                                <label class="info_left">备注:</label>
                                <label class="info_right" id="search_comments">—</label>
                            </div>
                        </form>

                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="modal-footer-btn-search">
                        修改
                    </button>
                </div>
            </div>
        </div>
    </div>


    <!-- ModalUpdate -->
    <div class="modal fade" id="myModalUpdate" tabindex="-1" role="dialog" aria-labelledby="myModalLabelUpdate">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabelUpdate">修改待办事项</h4>
                </div>
                <div class="modal-body">

                    <div style="text-align: left">

                        <form>
                            <div class="form-group">
                                <label class="info_left">待办事项标题:</label>
                                <input class="info_right" id="update_todoItemTitle" style="width: 400px">
                                <input class="info_right" id="update_todoItemId" style="display: none">
                            </div>
                            <div class="form-group">
                                <label class="info_left">待办事项内容:</label>
                                <br>
                                <input class="info_right" id="update_todoItemContent"
                                       style="height: 200px;width:400px ;margin-left: 100px">
                            </div>
                            <div class="form-group">
                                <label class="info_left">优先级:</label>

                                <select class="form-control info_right" style="width: 400px;margin-left: 100px"
                                        id="update_priority">
                                    <option value="LOW">LOW</option>
                                    <option value="MEDIUM">MEDIUM</option>
                                    <option value="HIGH">HIGH</option>
                                </select>

                            </div>
                            <div class="form-group">
                                <label class="info_left">备注:</label>
                                <input class="info_right" id="update_comments" style="width: 400px">
                            </div>
                        </form>

                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="close()">关闭</button>
                    <button type="button" class="btn btn-primary" id="modal-footer-btn-update" onclick="updateItems()">
                        保存
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        $('#table').bootstrapTable({
            url: '/items/listItems',
            pagination: true,
            clickToSelect: true,                //是否启用点击选中行
            toolbar: '#toolbar',                //工具按钮用哪个容器
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'todoItemTitle',
                    title: '代办事项标题'
                }, {
                    field: 'todoItemContent',
                    title: '待办事项内容'
                }, {
                    field: 'priority',
                    title: '优先级'
                }, {
                    field: 'creationDate',
                    title: '创建时间'
                }, {
                    field: 'lastUpadateDate',
                    title: '更新时间'
                }, {
                    field: 'comments',
                    title: '备注'
                }]
        });

        $(function () {
            $.ajax({
                url: '/user/selectUserInfomationById',
                type: 'POST',
                async: true,
                dataType: 'json',
                success: function (data, textStatus, jqXHR) {
                    console.log(data);
                    document.getElementById('hidden-xs').innerText = data.userName;
                },
                error: function (xhr, textStatus) {
                    console.log('查询错误')

                },

            })

        });

        $('#table').on('click-row.bs.table', function (row, $element) {

            $('#myModal').modal('show');
            if ($element.todoItemTitle != null) {
                document.getElementById('search_todoItemTitle').innerText = $element.todoItemTitle;
            }
            if ($element.todoItemContent != null) {
                document.getElementById('search_todoItemContent').innerText = $element.todoItemContent;
            }
            if ($element.priority != null) {
                document.getElementById('search_priority').innerText = $element.priority;
            }
            if ($element.creationDate != null) {
                document.getElementById('search_creationDate').innerText = $element.creationDate;
            }
            if ($element.lastUpadateDate != null) {
                document.getElementById('search_lastUpadateDate').innerText = $element.lastUpadateDate;
            }
            if ($element.comments != null) {
                document.getElementById('search_comments').innerText = $element.comments;
            }


            console.log($element);
        });


        var $table = $('#table'),
            $button_1 = $('#modal-footer-btn-search'),
            $button_2 = $('#btn_edit');

        $(function () {
            $button_1.click(function () {
                var data = $table.bootstrapTable('getSelections');
                $('#myModal').modal('hide');
                document.getElementById('update_todoItemId').value = data["0"].todoItemId;
                document.getElementById('update_todoItemTitle').value = data["0"].todoItemTitle;
                document.getElementById('update_todoItemContent').value = data["0"].todoItemContent;
                document.getElementById('update_priority').value = data["0"].priority;
                document.getElementById('update_comments').value = data["0"].comments;
                $('#myModalUpdate').modal('show');
            });
        });

        /*toolbar中的修改按钮*/
        $(function () {
            $button_2.click(function () {

                var data = $table.bootstrapTable('getSelections');
                if (data.length != 1) {
                    alert("请选择一行进行修改");
                    return false;
                }
                $('#myModal').modal('hide');
                document.getElementById('update_todoItemId').value = data["0"].todoItemId;
                document.getElementById('update_todoItemTitle').value = data["0"].todoItemTitle;
                document.getElementById('update_todoItemContent').value = data["0"].todoItemContent;
                document.getElementById('update_priority').value = data["0"].priority;
                document.getElementById('update_comments').value = data["0"].comments;
                $('#myModalUpdate').modal('show');
            });
        });

        /*修改待办事项*/
        function updateItems() {
            var update_todoItemId = document.getElementById('update_todoItemId').value;
            var update_todoItemTitle = document.getElementById('update_todoItemTitle').value;
            var update_todoItemContent = document.getElementById('update_todoItemContent').value;
            var update_priority = document.getElementById('update_priority').value;
            var update_comments = document.getElementById('update_comments').value;

            if (update_todoItemTitle == "") {
                alert("请填写事项题目");
                return false;
            }
            if (update_todoItemContent == "") {
                alert("请填写事项题目");
                return false;
            }
            if (update_priority == "") {
                alert("请填写事项优先级");
                return false;
            }
            if (update_comments == "") {
                alert("请填写事项备注");
                return false;
            }
            if (update_todoItemId == "") {

                update_todoItemId = "deficiency";
            }
            $.ajax({
                url: '/items/updateItems',
                type: 'POST', //GET
                async: true,
                data: {
                    "update_todoItemId": update_todoItemId,
                    "update_todoItemTitle": update_todoItemTitle,
                    "update_todoItemContent": update_todoItemContent,
                    "update_priority": update_priority,
                    "update_comments": update_comments,
                },
                dataType: 'json',

                success: function (data, textStatus, jqXHR) {
                    console.log("操作成功");
                    alert("操作成功");
                    $('#myModalUpdate').modal('hide');
                    document.getElementById('update_todoItemId').value = "";
                    refresh();
                },
                error: function (xhr, textStatus) {
                    console.log('更新错误');
                    alert("更新错误");
                    $('#myModalUpdate').modal('hide');
                    document.getElementById('update_todoItemId').value = "";
                    refresh();
                },

            })


        }



        /*myModalUpdate隐藏时触发*/
        $(function () {
            $('#myModalUpdate').on('hide.bs.modal', function () {


                document.getElementById('update_todoItemId').value = "";
                document.getElementById('update_todoItemTitle').value = "";
                document.getElementById('update_todoItemContent').value = "";
                document.getElementById('update_priority').value = "";
                document.getElementById('update_comments').value = "";

            });
        });


            /*刷新表格*/
            function refresh() {
                $table.bootstrapTable('refresh', {url: "/items/listItems"});
            }

            function showInsert() {
                $('#myModalUpdate').modal('show');
            }

            function deleteItems() {

                var data = $table.bootstrapTable('getSelections');
                if (data.length == 0) {
                    alert("请选择要删除的行");
                    return false;
                }

                var dataList = new Array();
                for (var i = 0; i < data.length; i++) {
                    dataList.push(data[i].todoItemId);

                }

                alert("确定删除这" + data.length + "项吗");

                $.ajax({
                    url: '/items/deleteItems',
                    type: 'POST', //GET
                    async: true,    //或false,是否异步
                    data: {
                        "dataList": JSON.stringify(dataList),
                    },
                    dataType: 'json',

                    success: function (data, textStatus, jqXHR) {
                        if (data == 1) {
                            alert("删除成功");
                            refresh();
                        } else if (data == 0) {
                            alert("删除失败");
                            refresh();
                        }
                        console.log(data);
                    },
                    error: function (xhr, textStatus) {
                        console.log('错误');
                        alert("删除失败");
                        refresh();

                    },

                })


            }
    </script>

</div>
<!-- jQuery 3 -->
<script src="../../resources/styles/adminLTE/bower_components/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="../../resources/styles/adminLTE/bower_components/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.7 -->
<script src="../../resources/styles/adminLTE/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->
<script src="../../resources/styles/adminLTE/bower_components/raphael/raphael.min.js"></script>
<script src="../../resources/styles/adminLTE/bower_components/morris.js/morris.min.js"></script>
<!-- Sparkline -->
<script src="../../resources/styles/adminLTE/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap -->
<script src="../../resources/styles/adminLTE/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../../resources/styles/adminLTE/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- jQuery Knob Chart -->
<script src="../../resources/styles/adminLTE/bower_components/jquery-knob/dist/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="../../resources/styles/adminLTE/bower_components/moment/min/moment.min.js"></script>
<script src="../../resources/styles/adminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- datepicker -->
<script src="../../resources/styles/adminLTE/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="../../resources/styles/adminLTE/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<!-- Slimscroll -->
<script src="../../resources/styles/adminLTE/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../resources/styles/adminLTE/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../resources/styles/adminLTE/dist/js/adminlte.min.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="../../resources/styles/adminLTE/dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../resources/styles/adminLTE/dist/js/demo.js"></script>
</body>
</html>
